package com.example.mapper;

import com.example.entity.Venue;
import com.example.entity.VenueOrder;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface VenueMapper {

    //查询全部场地
    @Select("select * from venue")
    List<Venue> queryAllVenue();

    //通过ID查询场地
    @Select("select * from venue where venueId=#{venueId}")
    Venue queryVenueById(int venueId);

    //通过名字模糊查询场地
    @Select("select * from venue where venueName like '%#{venueName}%'")
    List<Venue> queryVenueByName(String venueName);

    //添加场地
    @Insert("insert into venue (venueName,venueLocation,charges,announcement,\n" +
            "weeklyInfo,state,user,equipment,events)\n" +
            "values (#{venueName},#{venueLocation},#{charges},#{announcement},\n" +
            "#{weeklyInfo},#{state},#{user},#{equipment},#{events});")
    int addVenue(Venue venue);

    //删除场地
    @Delete("delete from venue where venueId=#{venueId}")
    int deleteVenue(int venueId);

    //修改场地
    @Update("update venue set venueName=#{venueName}, venueLocation=#{venueLocation},charges=#{charges},\n" +
            "announcement=#{announcement},weeklyInfo=#{weeklyInfo},state=#{state},user=#{user},\n" +
            "equipment=#{equipment},events=#{events}\n" +
            "where venueId=#{venueId};")
    int updateVenue(Venue venue);

    //更改场地状态
    @Update("update venue set state = #{state} where venueId = #{venueId}")
    int updateVenueState(int venueId,int state);

    //查询场地费用
    @Select("select charges from venue where venueId = #{venueId}")
    String venueCharges(int venueId);

    String announcement();

    //查询场地一周信息
    @Select("select weeklyInfo from venue where venueId = #{venueId}")
    String weeklyInfo(int venueId);

    //预定场地，保存订单信息
    @Insert("insert into venueorder (startTime,endTime,countTime,charges,countCharges,venueId)" +
            "values(#{startTime},#{endTime},#{countTime},#{charges},#{countCharges},#{venueId},)")
    int venueBook(VenueOrder venueOrder);
}
